#!/bin/zsh

ZSH_INSTALLED=`apk list zsh 2> /dev/null`
if [ -z ${ZSH_INSTALLED} ]; then
	echo "Installing zsh"
	apk add zsh
	echo "Installing zsh packages"
	# find packages to install 
	ZSH_PACKAGES=`apk search zsh- | grep ^zsh-[a-z]  | sed 's/-\d\+\(\.\d\+\)\?.*//g'`
	# install packages for zsh
	ZSH_INSTALL_CMDLINE="apk add --no-cache zsh fzf fzf-zsh-plugin"
	for package in ${ZSH_PACKAGES};
	do
		ZSH_INSTALL_CMDLINE="${ZSH_INSTALL_CMDLINE} $package"
	done
	zsh -c "${ZSH_INSTALL_CMDLINE}"
fi

# install configuration
if [ -f /srv/zsh/zshrc ]; then
	cp /srv/zsh/zshrc ~/.zshrc
fi
